#ifndef TABLE_H
#define TABLE_H
#include "interpreter.h"
class MyTable {
public:
    /* initialize the shared string system */
    static void TableInit(Interpreter *pc);


    /* initialize a table */
    static void TableInitTable(Table *tbl, TableEntry **hashTable, int size,
                        int onHeap);


    /* set an identifier to a Value. returns FALSE if it already exists.
     * key must be a shared string from TableStrRegister() */
    static int TableSet(Interpreter *pc, Table *tbl, char *key, Value *val,
                        const char *declFileName, int declLine, int declColumn);

    /* find a Value in a table. returns FALSE if not found.
     * key must be a shared string from TableStrRegister() */
    static int TableGet(Table *tbl, const char *key, Value **val,
                 const char **declFileName, int *declLine, int *declColumn);

    /* remove an entry from the table */
    static Value *TableDelete(Interpreter *pc, Table *tbl, const char *key);


    /* set an identifier and return the identifier. share if possible */
    static char *TableSetIdentifier(Interpreter *pc, Table *tbl, const char *ident,
                             int IdentLen);

    /* register a string in the shared string store */
    static char *TableStrRegister2(Interpreter *pc, const char *str, int len);

    static char *TableStrRegister(Interpreter *pc, const char *str);

    /* free all the strings */
    static void TableStrFree(Interpreter *pc);

private:
    static unsigned int TableHash(const char *key, int Len);
    static TableEntry *TableSearch(Table *tbl, const char *key,
                                   int *addAt);
    static TableEntry *TableSearchIdentifier(Table *tbl,
                                             const char *key, int len, int *addAt);
};
#endif //TABLE_H
